# -*- coding: utf-8 -*-
import pytest
from common_method import check_code_and_msg
from service.utilsApi.baseApi import BaseApi


class LoginClass(object):
    def __init__(self, domain):
        # 基础变量
        self.common = BaseApi(domain)
    def opendemoapi(self, errMsg=None):
        '''demoapp登录'''
        # 接口地址
        uri = '/api/auth/login'
        payload = {
          "username": "leibin",
          "password": "123456"
        }
        headers = {
            'Content-Type': 'application/json'
        }

        response = self.common.post(uri=uri, params=payload , headers=headers)
        try:
            check_code_and_msg(response, expected_msg='登录成功', expected_code=200)
            return response['data']
        except (KeyError, json.JSONDecodeError) as e:
            pytest.fail(f"登录失败: {str(e)}")

